﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UYD_WCS_AS_AGV_Controller
{
    public  class BasicInfo
    {
        public static WCSService.Service WcsService { get; set; }
        public static AgvHelper AgvService { get; set; }
        public static void Init()
        {
            UYD_WCS.Common.INIFile iniFile = new UYD_WCS.Common.INIFile(Application.ExecutablePath + "../../SYS.ini");
            try
            {
                string uri = iniFile.IniReadValue("ForWCS", "ServieUri");
                WcsService = new WCSService.Service(uri);


            }
            catch(Exception ex)
            {
                BaseClass.Log.saveToLog(BaseClass.Log.locType.Wcs, "WCS服务启动失败：" + ex.Message + Environment.NewLine + ex.StackTrace);
            }
            int iAgvConnectCount = 0;
            while (true)
            {
                if (AgvService != null)
                    if (AgvService.AgvConneed)
                        break;
                if (iAgvConnectCount >= 1)
                    break;
                try
                {
                    AgvService = new AgvHelper(iniFile.IniReadValue("ForAgv", "AgvIP"));
                    //AgvService = new AgvHelper("192.168.1.4");
                }
                catch (Exception ex)
                {
                    //WCSService.Service.WriteLog("AGV服务连接失败：" + ex.Message + Environment.NewLine + ex.StackTrace); "WCS服务启动失败：" + ex.Message + Environment.NewLine + ex.StackTrace
                    BaseClass.Log.saveToLog(BaseClass.Log.locType.Agv, "WCS服务启动失败：" + ex.Message + Environment.NewLine + ex.StackTrace);
                }
                iAgvConnectCount++;
            }
        }
    }
}
